package com.sumainfor.pc.gmio.controller.housekeeper;

import com.sumainfor.common.util.JsonResult;
import com.sumainfor.common.utlis.PageUtils;
import com.sumainfor.common.utlis.Pager;
import com.sumainfor.pc.gmio.service.HoTenantBillService;
import com.sumainfor.pc.gmio.service.SeTenantBillService;
import com.sumainfor.pc.gmio.service.impl.HoTenantBillExxxSerivceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * 服务管家租客账单
 */
@RestController
@RequestMapping("/housekeeper/HoTenantBill")
public class HoTenantBillController implements Serializable {
    @Autowired
    private HoTenantBillService hoTenantBillService;

    @Autowired
    private HoTenantBillExxxSerivceImpl hoTenantBillExxxSerivce;

    /**
     * 通过客户编号查询历史账单列表
     * @param params
     * @param pager
     * @return
     */
    @GetMapping("/getTenantBillListByTenIdl")
    public JsonResult getTenantBillListByTenIdl(@RequestParam Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=hoTenantBillService.getTenantBillListCountByTenId(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=hoTenantBillService.getTenantBillListByTenId(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *通过客户编号查询剩余未缴费账单和待审核账单和逾期账单
     */
    @GetMapping("/getTenantBillListByTenIdwd")
    public JsonResult getTenantBillListByTenIdwd(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=hoTenantBillService.getTenantBillListByTenId(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return  result;
    }
    /**
     * 服务管家查询账单中心列表
     * @param params
     * @param pager
     * @return
     */
    @PostMapping("/getHoTenantBillList")
    public JsonResult getHoTenantBillList(@RequestBody Map<String,Object>params,Pager pager){
        JsonResult result=new JsonResult();
        String a=params.get("biTypeList").toString();
        if (a.equals("")) {//审核是否通过
            params.put("biTypeList", null);
        }else{
            params.put("biTypeList",  a.split(","));
        }
        pager.setPageno(Integer.parseInt(params.get("pageno").toString()));
        pager.setPagesize(Integer.parseInt(params.get("pagesize").toString()));
        pager.setPagerNecessary(params, pager);
        PageUtils pageUtils = new PageUtils();
        Integer cout=hoTenantBillService.getHoTenantBillListCount(params);
        if(cout==0){
            return pageUtils.getJsonResult(new ArrayList<Map<String,Object>>(), params,cout);
        }
        List<Map<String,Object>>getCommunityList=hoTenantBillService.getHoTenantBillList(params);
        result=pageUtils.getJsonResult(getCommunityList, params, cout);
        return result;
    }
    /**
     *填写退租表时查询未缴费账单
     */
    @GetMapping("/getTenantBillWithdraList")
    public JsonResult getTenantBillWithdraList(@RequestParam Map<String,Object>params){
        JsonResult result=new JsonResult();
        List<Map<String,Object>> list=hoTenantBillService.getTenantBillWithdraList(params);
        if (list!=null){
            result.put(list);
        }else{
            result.putFailed("服务器繁忙");
        }
        return  result;
    }
    /**
     *退租账单根据客户编号和房源详表编号查询合同已产生的金额
     */
    @GetMapping("/getHoProduceMoney")
    public JsonResult getHoProduceMoney(@RequestParam Map<String,Object>params){
        return hoTenantBillService.getHoProduceMoney(params);
    }

    /**
     *根据账单来源编号查询账单的相关信息（维修师傅我的工单的账单详细）
     */
    @GetMapping("/getBillListForReapir")
    public JsonResult getBillListForReapir(@RequestParam Map<String,Object>params){
        return hoTenantBillService.getBillListForReapir(params);
    }





    /**
     * 退租账单根据客户编号和房源详表编号查询合同已产生的金额
     * @author zhoucong
     * @data 2019/10/24
     * @Param
     * @return
     */
    @GetMapping("/getHoProduceMoneyExt")
    public JsonResult getHoProduceMoneyExt(@RequestParam Map<String,Object> params){
        return hoTenantBillExxxSerivce.getHoProduceMoneyExt(params);
    }

}
